package com.xlblog.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xlblog.blog.entity.*;
import com.xlblog.blog.mapper.*;
import com.xlblog.blog.service.TCountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xlblog.blog.service.TTagService;
import com.xlblog.blog.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional(rollbackFor=Exception.class)  //开启事务
@Service
public class TCountServiceImpl extends ServiceImpl<TCountMapper, TCount> implements TCountService {

    @Autowired
    TCountMapper tCountMapper;

    // 访问量
    @Override
    public int countBlog() {
        TCount tCount = new TCount();
//        //获取当前访问量
        long count = tCountMapper.getCount();

        //修改数据库中的count
        long  i = 1;
        tCount.setId(i);
        tCount.setCount(count += 1); //访问量+1
        tCountMapper.updateById(tCount);

        //获取新的访问量
        return tCountMapper.getCount();
    }
}
